# Maintainer: Maxime Gauduin <alucryd@archlinux.org>
# Maintainer: T.J. Townsend <blakkheim@archlinux.org>
# Contributor: Bartłomiej Piotrowski <nospam@bpiotrowski.pl>

# ALARM: Kevin Mihelich <kevin@archlinuxarm.org>
#  - disable LTO: -DENABLE_LTO='FALSE'

pkgbase=vbam
pkgname=(
  vbam-sdl
  vbam-wx
)
_pkgname=visualboyadvance-m
pkgver=2.1.9
pkgrel=3
pkgdesc='Nintendo GameBoy Advance emulator'
arch=(x86_64)
url='https://visualboyadvance-m.org'
license=(GPL2)
depends=(
  glu
  libsfml-network.so
  libsfml-system.so
  libgl
  libpng
  sdl2
  sfml
  zlib
)
makedepends=(
  cmake
  doctest
  ffmpeg
  git
  libglvnd
  ninja
  wxwidgets-gtk3
  zip
)
source=("git+https://github.com/${_pkgname}/${_pkgname}.git?signed#tag=v${pkgver}")
b2sums=('dc81587a63b823217d86274e79d78f764a82c1244965646be41e9bfd382d9b457f695d95ba873c6a5150184dc0555d482d8db1f4aa0917e4342d9baa2c36def1')
validpgpkeys=(A0C0E526E36FD2138C149D4D08AB596679D86240) # Rafael Kitover <rkitover@gmail.com>

prepare() {
  cd ${_pkgname}
  git cherry-pick -n 6766b9ca54e736e200ec652b4d4ff78fca6326dd
  # Unbundle doctest (bundled one is not glibc 2.34 compatible)
  sed -e 's|${CMAKE_SOURCE_DIR}/third_party|/usr|' -i src/wx/tests/CMakeLists.txt
}

#pkgver() {
#  cd ${_pkgname}
#  git describe --tags | sed 's/^v//; s/-/.r/; s/-g/./'
#}

build() {
  cmake -S ${_pkgname} -B build-sdl -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_SKIP_RPATH=TRUE \
    -DENABLE_SDL=TRUE \
    -DENABLE_WX=FALSE \
    -DENABLE_LINK=TRUE \
    -DENABLE_LTO=FALSE \
    -Wno-dev
  cmake --build build-sdl

  cmake -S ${_pkgname} -B build-wx -G Ninja \
    -DCMAKE_BUILD_TYPE=Release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DCMAKE_SKIP_RPATH=TRUE \
    -DENABLE_SDL=FALSE \
    -DENABLE_WX=TRUE \
    -DENABLE_FFMPEG=TRUE \
    -DENABLE_LINK=TRUE \
    -DENABLE_LTO=FALSE \
    -Wno-dev
  cmake --build build-wx
}

package_vbam-sdl() {
  backup=(etc/vbam.cfg)
  conflicts=(vbam-wx)

  DESTDIR="${pkgdir}" cmake --install build-sdl
}

package_vbam-wx() {
  depends+=(
    glib2
    gtk3
    libavcodec.so
    libavformat.so
    libavutil.so
    libswscale.so
    openal
    wxwidgets-gtk3
    zip
  )
  conflicts=(vbam-sdl)

  DESTDIR="${pkgdir}" cmake --install build-wx
}

# vim: ts=2 sw=2 et:
